package com.ozo.boot.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.boot.common.base.model.*;
import com.ozo.boot.common.base.model.BasePage;
import com.ozo.boot.common.base.model.PageResult;
import com.ozo.boot.common.base.model.ResultVO;
import com.ozo.boot.common.log.annotation.OperateLog;
import com.ozo.boot.system.pojo.dto.SysLoginLogQueryDTO;
import com.ozo.boot.system.pojo.vo.SysLoginLogVO;
import com.ozo.boot.system.service.ISysLoginLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

/**
 * 登录日志 前端控制器
 *
 * @author qiangesoft
 * @version 1.0
 * @date 2024-11-20 15:14:30
 */
@Tag(name = "登录日志")
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/loginLog")
public class SysLoginLogController {

    private final ISysLoginLogService sysLoginLogService;

    @OperateLog(value = "删除登录日志", module = "登录日志")
    @SaCheckPermission("system:loginLog:remove")
    @Operation(summary = "删除登录日志")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        sysLoginLogService.remove(batchDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "清空登录日志", module = "登录日志")
    @SaCheckPermission("system:loginLog:clear")
    @Operation(summary = "清空登录日志")
    @DeleteMapping("/clear")
    public ResultVO<Void> clear() {
        sysLoginLogService.clear();
        return ResultVO.success();
    }

    @SaCheckPermission("system:loginLog:page")
    @Operation(summary = "登录日志分页")
    @GetMapping("/page")
    public ResultVO<PageResult<SysLoginLogVO>> page(@Valid BasePage basePage, SysLoginLogQueryDTO queryDTO) {
        return ResultVO.success(sysLoginLogService.page(basePage, queryDTO));
    }

}